`true` is mapped to `2`, which matches current behavior.
pub codegen_units: Option<u32>, // None = use rustc default
pub rustc_args: Option<Vec<String>>,
pub rustdoc_args: Option<Vec<String>>,
- pub debuginfo: bool,
+ pub debuginfo: Option<u32>,
pub debug_assertions: bool,
pub rpath: bool,
pub test: bool,
#[derive(RustcEncodable)]
struct SerializedProfile<'a> {
opt_level: &'a str,
- debuginfo: bool,
+ debuginfo: Option<u32>,
debug_assertions: bool,
test: bool,
}
impl Profile {
pub fn default_dev() -> Profile {
Profile {
- debuginfo: true,
+ debuginfo: Some(2),
debug_assertions: true,
..Profile::default()
}
pub fn default_release() -> Profile {
Profile {
opt_level: "3".to_string(),
- debuginfo: false,
+ debuginfo: None,
..Profile::default()
}
}
codegen_units: None,
rustc_args: None,
rustdoc_args: None,
- debuginfo: false,
+ debuginfo: None,
debug_assertions: false,
rpath: false,
test: false,
Kind::Host => cx.host_triple(),
Kind::Target => cx.target_triple(),
})
- .env("DEBUG", &profile.debuginfo.to_string())
+ .env("DEBUG", &profile.debuginfo.is_some().to_string())
.env("OPT_LEVEL", &profile.opt_level)
.env("PROFILE", if cx.build_config.release { "release" } else { "debug" })
.env("HOST", cx.host_triple())
let profile = cx.lib_profile();
let mut opt_type = String::from(if profile.opt_level == "0" { "unoptimized" }
else { "optimized" });
- if profile.debuginfo {
+ if profile.debuginfo.is_some() {
opt_type = opt_type + " + debuginfo";
}
let duration = start_time.elapsed();
resolve: &'a Resolve,
config: &'cfg Config,
build_config: BuildConfig,
- profiles: &'a Profiles,
+ profiles: &'a Profiles,
exec: Arc<Executor>)
-> CargoResult<Compilation<'cfg>> {
let units = pkg_targets.iter().flat_map(|&(pkg, ref targets)| {
}
}
- if debuginfo {
- cmd.arg("-g");
+ if let Some(debuginfo) = debuginfo {
+ cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
}
if let Some(ref args) = *rustc_args {
}
}
+#[derive(RustcDecodable, Clone)]
+pub enum U32OrBool {
+ U32(u32),
+ Bool(bool),
+}
+
#[derive(RustcDecodable, Clone, Default)]
pub struct TomlProfile {
opt_level: Option<TomlOptLevel>,
lto: Option<bool>,
codegen_units: Option<u32>,
- debug: Option<bool>,
+ debug: Option<U32OrBool>,
debug_assertions: Option<bool>,
rpath: Option<bool>,
panic: Option<String>,
fn merge(profile: Profile, toml: Option<&TomlProfile>) -> Profile {
let &TomlProfile {
- ref opt_level, lto, codegen_units, debug, debug_assertions, rpath,
+ ref opt_level, lto, codegen_units, ref debug, debug_assertions, rpath,
ref panic
} = match toml {
Some(toml) => toml,
None => return profile,
};
+ let debug = match *debug {
+ Some(U32OrBool::U32(debug)) => Some(Some(debug)),
+ Some(U32OrBool::Bool(true)) => Some(Some(2)),
+ Some(U32OrBool::Bool(false)) => Some(None),
+ None => None,
+ };
Profile {
opt_level: opt_level.clone().unwrap_or(TomlOptLevel(profile.opt_level)).0,
lto: lto.unwrap_or(profile.lto),
# The development profile, used for `cargo build`.
[profile.dev]
opt-level = 0 # controls the `--opt-level` the compiler builds with
-debug = true # controls whether the compiler passes `-g`
+debug = true # controls whether the compiler passes `-C debuginfo`
+ # a value of `true` is equivalent to `2`
rpath = false # controls whether the compiler passes `-C rpath`
lto = false # controls `-C lto` for binaries and staticlibs
debug-assertions = true # controls whether debug assertions are enabled
# The testing profile, used for `cargo test`.
[profile.test]
opt-level = 0
-debug = true
+debug = 2
rpath = false
lto = false
debug-assertions = true
# The documentation profile, used for `cargo doc`.
[profile.doc]
opt-level = 0
-debug = true
+debug = 2
rpath = false
lto = false
debug-assertions = true
format!("\
[COMPILING] {name} v{version} ({url})
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
execs().with_status(101)
.with_stderr(&format!("\
[COMPILING] bar v0.5.0 ({url})
-[RUNNING] `rustc --crate-name test {dir}{sep}src{sep}lib.rs --crate-type lib -g \
+[RUNNING] `rustc --crate-name test {dir}{sep}src{sep}lib.rs --crate-type lib -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=-[..] \
--out-dir {dir}{sep}target \
[RUNNING] `rustc [..] a[/]build.rs [..] --extern b=[..]`
[RUNNING] `[..][/]a-[..][/]build-script-build`
[RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..]target[/]debug[/]deps \
-L [..]target[/]debug[/]deps`
[COMPILING] foo v0.5.0 (file://[..])
[RUNNING] `rustc --crate-name build_script_build build.rs --crate-type bin \
--emit=dep-info,link \
- -g -C metadata=[..] --out-dir [..] \
+ -C debuginfo=2 -C metadata=[..] --out-dir [..] \
-L [..]target[/]debug[/]deps \
--extern a=[..]liba[..].rlib`
[RUNNING] `[..][/]foo-[..][/]build-script-build`
[RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L [..]target[/]debug[/]deps`
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
--emit=dep-info,link \
- -C prefer-dynamic -g \
+ -C prefer-dynamic -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
--emit=dep-info,link \
- -C prefer-dynamic -g \
+ -C prefer-dynamic -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
execs().with_status(0).with_stderr(&format!("\
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
"reason":"compiler-artifact",
"profile": {
"debug_assertions": true,
- "debuginfo": true,
+ "debuginfo": 2,
"opt_level": "0",
"test": false
},
"target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
"profile": {
"debug_assertions": true,
- "debuginfo": true,
+ "debuginfo": 2,
"opt_level": "0",
"test": false
},
"target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
"profile":{
"debug_assertions":true,
- "debuginfo":true,
+ "debuginfo":2,
"opt_level":"0",
"test":false
},
.with_stderr_contains(&format!("\
[COMPILING] foo v0.5.0 ({url})
[RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]{target}[/]debug[/]deps \
--target {target} \
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
- -g \
+ -C debuginfo=2 \
+ -C metadata=[..] \
+ --out-dir [..] \
+ -L dependency={dir}[/]target[/]debug[/]deps`
+[FINISHED] [..] target(s) in [..]
+",
+dir = p.root().display(),
+url = p.url()
+)));
+}
+
+#[test]
+fn debug_override_1() {
+ let mut p = project("foo");
+
+ p = p
+ .file("Cargo.toml", r#"
+ [package]
+ name = "test"
+ version = "0.0.0"
+ authors = []
+
+ [profile.dev]
+ debug = 1
+ "#)
+ .file("src/lib.rs", "");
+ assert_that(p.cargo_process("build").arg("-v"),
+ execs().with_status(0).with_stderr(&format!("\
+[COMPILING] test v0.0.0 ({url})
+[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
+ --emit=dep-info,link \
+ -C debuginfo=1 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C opt-level={level} \
- -g \
+ -C debuginfo=2 \
-C debug-assertions=on \
-C metadata=[..] \
--out-dir [..] \
--emit=dep-info,link \
-C prefer-dynamic \
-C opt-level=1 \
- -g \
+ -C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]release[/]deps \
-L dependency={dir}[/]target[/]release[/]deps`
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C opt-level=1 \
- -g \
+ -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]release[/]deps \
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \
--emit=dep-info,link \
- -g \
+ -C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]debug[/]deps \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name a examples[/]a.rs --crate-type bin \
--emit=dep-info,link \
- -g \
+ -C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]debug[/]examples \
-L dependency={dir}[/]target[/]debug[/]deps \
.with_stderr(format!("\
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
.with_stderr(format!("\
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C debug-assertions=off \
-C metadata=[..] \
--out-dir [..] \
.with_stderr(&format!("\
[COMPILING] {name} v{version} ({url})
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[RUNNING] `rustc --crate-name {name} src[/]main.rs --crate-type bin \
- --emit=dep-info,link -g \
+ --emit=dep-info,link -C debuginfo=2 \
-C debug-assertions \
-C metadata=[..] \
--out-dir [..] \
.with_status(0)
.with_stderr(format!("\
[COMPILING] foo v0.0.1 ({url})
-[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link -g \
- -C metadata=[..] \
+[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \
+ -C debuginfo=2 -C metadata=[..] \
--out-dir [..]`
-[RUNNING] `rustc --crate-name bar src[/]bin[/]bar.rs --crate-type bin --emit=dep-info,link -g \
- -C debug-assertions [..]`
+[RUNNING] `rustc --crate-name bar src[/]bin[/]bar.rs --crate-type bin --emit=dep-info,link \
+ -C debuginfo=2 -C debug-assertions [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", url = p.url())));
}
.with_status(0)
.with_stderr(format!("\
[COMPILING] foo v0.0.1 ({url})
-[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link -g \
- -C metadata=[..] \
+[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \
+ -C debuginfo=2 -C metadata=[..] \
--out-dir [..]`
-[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -g \
+[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -C debuginfo=2 \
-C debug-assertions [..]--test[..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", url = p.url())));
.with_status(0)
.with_stderr(format!("\
[COMPILING] bar v0.1.0 ([..])
-[RUNNING] `[..] -g [..]`
+[RUNNING] `[..] -C debuginfo=2 [..]`
[COMPILING] foo v0.0.1 ({url})
-[RUNNING] `[..] -g -C debug-assertions [..]`
+[RUNNING] `[..] -C debuginfo=2 -C debug-assertions [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", url = foo.url())));
}